/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function TableSalle(myparent, refreshInterval){
    this.parents = myparent;
    this.refreshInterval = refreshInterval;
    this.salles = new Array();
    this.loadObject = function(json){
        $(this.parents).html("");
        this.salles = new Array();
        for(var i=0; i < json.length;i++){
            var salle = json[i];
            var jSalle = new Salle("","", new Array());
            jSalle.loadJson(salle);
            this.salles.push(jSalle);
        }
    };
    this.generateTable = function(){
        $(this.parents).html("");
        var table = $("<table>",{
            class : "ui-widget ui-widget-content"
        });
        var header = $("<thead>");
        header.append(this.generateHeader());
        table.append(header);
        var body = $("<tbody>")
        for(var i = 0 ; i <this.salles.length; i++){
            var salle = this.salles[i];
            body.append(this.generateSalle(salle));
        }
        table.append(body)
        var footer = $("<tfoot>");
        footer.append(this.generateHeader());
        table.append(footer);
        var button = $("<button>",{
            text : "Ajouter une salle",
            click : function(){
                $("#dialog-form-salle").dialog("open");
            }
        });
        $(this.parents).append(button);
        $(this.parents).append(table);
    }
    this.generateHeader = function(){
        var element = $("<tr>",{
            class : "ui-widget-header"
        });
        var nom = $("<td>",{
            text : "Nom",
        });
        var machines = $("<td>",{
            text : "Nombre de machines",
        });
        var incidents = $("<td>",{
            text : "Nombre d'incidents"
        });
        var link = $("<td>",{
            text : "Détails"
        });
        element.append(nom);
        element.append(machines);
        element.append(incidents);
        element.append(link);
        return element;
    }
    this.generateSalle = function(salle){
        var element = $("<tr>",{
//            class : "table-salle"
        });
        var name = $("<td>",{
            text : salle.getName(),
        });
        var machines = $("<td>",{
            text : salle.getMachines().length,
        });
        var incidents = $("<td>",{
            text : "TODO"
        });
        var link = $("<td>",{
        });
        var a = $("<a>",{
            text: 'Lien',
            title: 'Voir/Modifier',
            href: '#',
            click: function(){ 
                
            }
        });
        link.append(a);
        element.append(name);
        element.append(machines);
        element.append(incidents);
        element.append(link);
        
        return element;
    };
}